package com.woniu.cms.contract.core.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.cms.contract.core.entity.Bid;
import com.woniu.cms.contract.core.entity.BidResultManagement;
import com.woniu.cms.contract.core.entity.BidResultVo;
import com.woniu.cms.contract.core.service.IBidResultManagementService;
import com.woniu.cms.contract.core.service.IBidService;
import com.woniu.common.api.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author maple leaf
 * @since 2022-09-17
 */
@RestController
@RequestMapping("/bid-result-management")
@Api(tags = "投标单管理")
public class BidResultManagementController {


    @Autowired
    private IBidResultManagementService bidResultManagementService;

    @Autowired
    private IBidService bidService;

    /*
    * 每个审批人都可以有多个客户
    * */
    @ApiOperation("查询审批表")
    @GetMapping
    public Result queryAudit(Integer currentPage,Integer pageSize){
        Page<Bid> page = new Page<>(currentPage,pageSize);
        QueryWrapper<Bid> wrapper = new QueryWrapper<>();

        wrapper.eq("state",1);
        Page<Bid> bidPage = bidService.page(page, wrapper);

        List<Bid> records = bidPage.getRecords();

        long total = bidPage.getTotal();

        HashMap<String, Object> map = new HashMap<>();
        map.put("total",total);
        map.put("records",records);

        return Result.common(map);
    }

    @ApiOperation("查询编辑审批单")
    @GetMapping("/bid/{bidCode}")
    public Result auditQueryBid(@PathVariable String bidCode){
        QueryWrapper<Bid> wrapper = new QueryWrapper<>();

        wrapper.eq("bid_code",bidCode);

        Bid bid = bidService.getOne(wrapper);

        return Result.common(bid);
    }


    @PostMapping
    public Result auditBid(@RequestBody BidResultManagement bidResultManagement){


        boolean b = bidResultManagementService.save(bidResultManagement);

        return b == true ? Result.ok() : Result.error();

    }




}

